package main.java.DMDE.persistence;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import main.java.DMDE.model.Parameter;
import main.java.common.IXmlManager;

public class ParameterXmlManager implements IXmlManager<Parameter> {

	private TypeXmlManager typeManager = new TypeXmlManager();
	
	public Element getElementFromItem(Parameter parameter, Document document) {
		Element typeElement = document.createElement("parameter");
		typeElement.setAttribute("name", parameter.getName().toString());
		typeElement.appendChild(typeManager.getElementFromItem(parameter.getType(), document));
		return typeElement;
	}

	@Override
	public Parameter getItemFromXmlElement(Element element) throws Exception {
		Parameter parameter = new Parameter();
		parameter.setName(element.getAttribute("name"));
		parameter.setType(typeManager.getItemFromXmlElement((Element) element.getChildNodes().item(0)));
		return parameter;
	}
}
